using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using AFI.Speargun.Web.Core;
using AFI.Speargun.Web.Paging;
using AFI.Speargun.Web.Models;
using System.Web.Security;

namespace AFI.Speargun.Web.Controllers
{
    public class InventoryCheckingController : BaseController
    {
        //
        // GET: /InventoryChecking/

        [Authorize]
        public ActionResult Index(int? page)
        {
            int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

            var inventoryCheckings = _service.ListInventoryCheckings().ToPagedList(currentPageIndex, pageSize);

            return View(inventoryCheckings);
        }

        //
        // GET: /InventoryChecking/Details/{id)

        [Authorize]
        public ActionResult Details(Guid id)
        {
            InventoryChecking inventoryChecking = _service.GetInventoryChecking(id);

            if (!inventoryChecking.DepartmentReference.IsLoaded)
                inventoryChecking.DepartmentReference.Load();

            if (!inventoryChecking.Department.AssetEntry.IsLoaded)
                inventoryChecking.Department.AssetEntry.Load();

            ViewData["InventoryChecking"] = inventoryChecking;

            return View(inventoryChecking);
        }

        //
        // GET: /InventoryChecking/Create

        [Authorize]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /InventoryChecking/Create

        [AcceptVerbs(HttpVerbs.Post)]
        [Authorize]
        public ActionResult Create(Guid DepartmentId)
        {
            InventoryChecking inventoryChecking = new InventoryChecking();
            inventoryChecking.CreateBy = (Guid)Membership.GetUser().ProviderUserKey;

            if (_service.CreateInventoryChecking(DepartmentId, inventoryChecking))
                return RedirectToAction("Details", new { id = inventoryChecking.InventoryCheckingId });

            return View();
        }
    }
}
